<?php

/*
parse CURIES (http://www.w3.org/TR/curie/) in pages and comments
example:
  this is a [wp:link] to wikipedia =>
  this is a <a href="http://en.wikipedia.org/wiki/link">link</a> to wikipedia
*/

$curies = array(
  "wikipedia" => "http://en.wikipedia.org/wiki/",
  "dictionary" => "http://dictionary.reference.com/browse/"
);

// do more to distinguish non-defined curies?
// make a way to define more without editing this file? (a page, perhaps..?)

function parse_curies($input) {
  global $curies;
  $final = "";
  $split = split("\]",$input);
  for($i=0; $i<count($split)-1; $i++) {
    $segment = $split[$i];
    $split2 = split("\[",$segment);
    $final .= $split2[0];
    $linkcontents = $split2[1];
    $split3 = split(":",$linkcontents);
    $baseURL = $curies[$split3[0]];
    if(!empty($baseURL)) {
      $final .= "<a href='".$baseURL.$split3[1]."'>".$split3[1]."</a>";
    } else {
      $final .= "<a href='' title='this is supposed to be a curie, but no one defined one for &quot;".$split3[0]."&quot;'>".$split3[1]."</a>";
    }
  }
  $final .= $split[count($split)-1];
  return $final;
}
add_filter(array('page_body','comment_body'),'parse_curies');
?>